/*
 *   ARMAGEDDON!!!
 *
 *   Written by: Mark Burns
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <phostpdk.h>

int
main(int argc, char *argv[])
{
    Uns16 ix;
    Uns16 race;
    char str[4];

    /* Parse our command-line parameters. First parameter, if any, is the
    game directory. Second parameter, if present, is the root directory. */

    switch (argc) {
     case 3:
        gRootDirectory = argv[2];
        /* FALL THROUGH */

     case 2:
        gGameDirectory = argv[1];
        /* FALL THROUGH */

     case 1:
        break;

     default:
        fprintf(stderr,"Usage: %s  [GameDirectory [RootDirectory]]\n", argv[0]);
        exit(1);
    }

    /* Initialize the PDK */
    InitPHOSTLib();

    if (! ReadGlobalData()) return 1;
    if (! ReadHostData()) return 1;

    /* drop all alliances. */
    for (race=1; race <= RACE_NR; race++) {
        if (PlayerIsActive(race)) {
            for (ix=1; ix <= RACE_NR; ix++) {
                if (ix != race && PlayerIsActive(ix) && PlayersAreAllies(race, ix)) {
                    AllyDropRequest(race, ix);
                }
            }
        }
    }

    srand(time(NULL));

    /* Now go through all of the ships. */
    for (ix=1; ix <= SHIP_NR; ix++) {
        if (IsShipExist(ix)) {
            if (ShipBeamNumber(ix) > 0 || ShipTubeNumber(ix) > 0 || ShipBays(ix) > 0) {
                PutShipMission(ix, Kill);
                PutShipEnemy(ix, NoRace);
                if (ShipCargo(ix, NEUTRONIUM) == 0)
                    PutShipCargo(ix, NEUTRONIUM, 10);

                /* Generate Random FC Number. */
                sprintf(str, "%d", (rand() % 1000));
                PutShipFC(ix, str);

                PutShipSpeed(ix, 0);
                PutShipLocationX(ix, 1258);
                PutShipLocationY(ix, 2917);
            }
        }
    }

    /* Write the files back to disk. */
    if (! WriteHostData()) return 1;

    /* Close down. No need to write any files back out to disk. */
    FreePHOSTLib();

    return 0;
}
